package cn.wyl.controller;

import cn.wyl.Result.JsonResult;
import cn.wyl.Store;
import cn.wyl.service.IStoreService;
import com.alibaba.csp.sentinel.annotation.SentinelResource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;

//用户服务：暴露接口给订单访问
@RestController
public class StoreController {

    @Autowired
    private IStoreService storeService;


    @PostMapping("/store/add")
    @SentinelResource(value="store",fallback = "fallbackHandler")
    public JsonResult add(@RequestBody Store store){
        // int i=1/0;
        try {
            storeService.add(store);
            return new JsonResult(true,"store添加成功");
        } catch (Exception e) {
            return new JsonResult(false,"store添加失败");
        }


    }

    // 熔断降级，参数和返回值与被熔断方法一致
    public JsonResult fallbackHandler(@RequestBody Store store){
        return new JsonResult(false,"被StoreController熔断了，store添加失败");
    }
}
